// Game.java
package fingergame;

import java.util.Scanner;

public class Game {
    private Person player1;
    private Computer player2;
    private int count;

    public Game() {
        this.player1 = new Person("玩家");
        this.player2 = new Computer("电脑");
        this.count = 0;
    }

    public void start() {
        while (player1.getHP() > 0 && player2.getHP() > 0) {
            count++;
            System.out.println("第 " + count + " 回合开始！");
            System.out.println(player1.getName() + "的HP：" + player1.getHP());
            System.out.println(player2.getName() + "的HP：" + player2.getHP());
            fight();
            System.out.println();
        }

        if (player1.getHP() <= 0) {
            System.out.println(player1.getName() + "的HP归零，游戏结束！电脑获胜！");
        } else {
            System.out.println(player2.getName() + "的HP归零，游戏结束！玩家获胜！");
        }
    }

    private void fight() {
        Card card1 = player1.chooseCard();
        Card card2 = player2.chooseCard();

        System.out.println(player1.getName() + "出牌：" + card1.getType());
        System.out.println(player2.getName() + "出牌：" + card2.getType());

        if (card1.getType().equals(card2.getType())) {
            System.out.println("平局，双方扣除5点HP！");
            player1.decreaseHP(5);
            player2.decreaseHP(5);
        } else if ((card1.getType().equals("剪刀") && card2.getType().equals("布")) ||
                (card1.getType().equals("石头") && card2.getType().equals("剪刀")) ||
                (card1.getType().equals("布") && card2.getType().equals("石头"))) {
            System.out.println(player1.getName() + "获胜！");
            player2.decreaseHP(10);
        } else {
            System.out.println(player2.getName() + "获胜！");
            player1.decreaseHP(10);
        }
    }
}
